# -*- coding: utf-8 -*-

import logging

from xadmin.lib.administrators import UserAdministrator
from xadmin.lib.sqlalchemy_driver import User
from xadmin.lib.base import *

log = logging.getLogger(__name__)

class LoginController(BaseController):

    def __init__(self):
        self.admin = UserAdministrator(User)

    def index(self):
        """POST /login: Verify if is a valid user."""
        user = request.params.get('username')
        password = request.params.get('password')
        response.headers['content-type'] = 'text/xml; charset=utf-8'
        if self.admin.isValid(user, password):
            return '<user valid="true" />'
        return '<user valid="false" />'